package com.kuson.springcloud.controller;

import com.kuson.springcloud.domain.CommonResult;
import com.kuson.springcloud.service.StorageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 库存前端控制器
 */
@RestController
@Slf4j
public class StorageController {
    @Resource
    private StorageService storageService;

    /**
     * 减库存
     * @param productId
     * @param count
     * @return
     */
    @RequestMapping("/storage/decrease")
    public CommonResult decrease(Long productId, Long count){
        int result=storageService.updateStorageById(productId,count);
        if(result>0){
            return new CommonResult(200,"扣减库存成功！");
        }else{
            return new CommonResult(444,"扣减库存失败！");

        }
    }
}
